package com.star.spring.deferred.service.juc.tools;


import java.util.concurrent.CountDownLatch;

/**
 * @description:
 * @author: star
 * @create: 2025-04-23 14:53
 **/

public class CountDownLatchTest {


    public static void main(String[] args) throws InterruptedException {

        //相当于计数器
        CountDownLatch countDownLatch = new CountDownLatch(6);
        //计数器总数是5,当减少为0,任务才继续向下执行
        for (int i = 1; i < 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "==>start");
                countDownLatch.countDown();
            }).start();
        }
        countDownLatch.await();
        System.out.println("main线程继续向下执行");
    }
}
